package com.example.myanimator.shadowLayer;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.Nullable;

import com.example.myanimator.R;

/**
 * @author tgw
 * @date 2021/3/30
 * @describe 图片阴影 纯色 猫咪阴影
 */
public class DrawBitmapShadow2 extends View {

    private Paint mPaint;
    private Bitmap mBitmap;
    private Bitmap mArgbBitmap;//纯色的图片

    public DrawBitmapShadow2(Context context) {
        super(context);
    }

    public DrawBitmapShadow2(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DrawBitmapShadow2(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void init() {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
        mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.aa);
        mArgbBitmap = mBitmap.extractAlpha();//绘制出 纯色的 猫咪图片 背影阴影

        mPaint = new Paint();
        mPaint.setAntiAlias(true); // 去除锯齿
        mPaint.setDither(true); // 抗抖动
        mPaint.setStrokeWidth(2);
        mPaint.setTextSize(100);//设置文字大小
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.BLACK);

    }

    @Override
    protected void onDraw(Canvas canvas) {

        canvas.drawColor(Color.WHITE);
        canvas.drawText("图片纯色阴影背景", 100, 100, mPaint);

        mPaint.setColor(Color.GRAY);
        canvas.drawBitmap(mArgbBitmap, null, new Rect(80, 50,  80+mArgbBitmap.getWidth(),
                50 + mArgbBitmap.getHeight()), mPaint);

        //相同位置绘制原图 盖在阴影上
//        mPaint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.INNER));
        canvas.drawBitmap(mBitmap, null, new Rect(60, 40,  mBitmap.getWidth(),
                40 + mBitmap.getHeight()), mPaint);



        //setMaskFilter()  该函数 不支持 硬件加速
        /**
         * Blur sty ：发光样式，有 Blur.INNER 内发光〕、 Blur.SOLID （外发光）、 Blur.NORMAL
         * （内外发光〉、  Blur.OUTER仅显示发光效果） 样式
         * */

        mPaint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.INNER));
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.FILL);
        canvas.drawCircle(300, 300, 50, mPaint);

    }




}
